package mm.chenchen.modules.sys.service.impl;
import mm.chenchen.common.constant.SeqConstant;
import mm.chenchen.constant.ResultMsg;

import mm.chenchen.db.annotation.DataSource;
import mm.chenchen.modules.sys.service.FastStartDictInfoService;
import mm.chenchen.modules.sys.service.FastStartSeqService;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import mm.chenchen.utils.R;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import mm.chenchen.modules.sys.entity.FastStartLabel;
import mm.chenchen.modules.sys.dao.FastStartLabelDao;
import mm.chenchen.modules.sys.service.FastStartLabelService;
import mm.chenchen.utils.PageUtils;
import mm.chenchen.utils.PageModel;

import java.util.Map;
import mm.chenchen.modules.sys.dao.model.request.FastStartLabelQuery;
import org.springframework.util.ObjectUtils;


@Service("fastStartLabelService")
////@DataSource("base")
public class FastStartLabelServiceImpl extends ServiceImpl<FastStartLabelDao, FastStartLabel> implements FastStartLabelService {

    @Autowired
    private FastStartSeqService seqService;

    public R findPage(Page<Map> page, FastStartLabelQuery param) {
        IPage<FastStartLabel> pageData = baseMapper.findPage(page, param);
        if (pageData != null) {
            return R.ok().setData(new PageModel(pageData.getRecords(),pageData.getTotal(),pageData.getSize(),pageData.getCurrent()));
        } else {
            return R.error(ResultMsg.DATA_NOT_EXIT);
        }
    }

    public R getById(Integer id){
        return R.ok().setData(super.getById(id));
    };

    public R saveInfo(FastStartLabel param){
        param.setId(seqService.nextVal(SeqConstant.LABEL_SEQ_ID_NAME));
        return R.ok().setData(super.save(param));
    };

    public R update(FastStartLabel param){
            FastStartLabel data=super.getById(param.getId());
            if(ObjectUtils.isEmpty(data)){
                return R.error(ResultMsg.DATA_NOT_EXIT);
            }
        return R.ok().setData(super.updateById(param));
    };

    public R deleteById(Integer id){
        return R.ok().setData(super.removeById(id));
    };

}